from typing import Dict
from .napi_gen_code import NapiGenCode
from .typescript_parser import TypeScriptDeclarationsParser
from .code_block import CodeBlock,LineCodeBlock

def parse_dts(dts_file: str) -> Dict[str, any]:
    parser = TypeScriptDeclarationsParser()
    # 解析文件
    try:
        result = parser.parse_file(dts_file)
    except Exception as e:
        print(f"解析错误: {e}")
        import traceback
        traceback.print_exc()
    return result

def gen_napi_code(result: Dict[str, any], nm_module: str, module_name: str) -> list[CodeBlock]:
    exporer = NapiGenCode(module_name, nm_module, result)
    return exporer.export_napi()

def gen_test_code(result: Dict[str, any], nm_module: str, module_name: str) -> list[CodeBlock]:
    exporer = NapiGenCode(module_name, nm_module, result)
    return [exporer.export_test()]